package com.ssm.subject.domain.handler.subejct;

import com.ssm.subject.common.enums.IsDeletedFlagEnum;
import com.ssm.subject.common.enums.SubjectInfoTypeEnum;
import com.ssm.subject.domain.bo.SubjectInfoBO;
import com.ssm.subject.domain.bo.SubjectOptionBO;
import com.ssm.subject.domain.convert.SubjectBriefConvert;
import com.ssm.subject.infra.basic.entity.SubjectBrief;
import com.ssm.subject.infra.basic.service.SubjectBriefService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 简答策略类
 */
@Component
public class BriefTypeHandle implements SubejctTypeHandler{
    @Resource
    private SubjectBriefService subjectBriefService;
    @Override
    public SubjectInfoTypeEnum getHandlerType() {
        return SubjectInfoTypeEnum.BRIEF;
    }

    @Override
    public void add(SubjectInfoBO subjectInfoBO) {
        //简答题目的插入
        SubjectBrief subjectBrief = SubjectBriefConvert.INSTANCE.subjectInfoBoToBrief(subjectInfoBO);
        subjectBrief.setSubjectId(subjectInfoBO.getId());
        subjectBriefService.insert(subjectBrief);
    }

    @Override
    public SubjectOptionBO query(Long subjectId) {
        SubjectBrief subjectBrief = new SubjectBrief();
        subjectBrief.setSubjectId(subjectId);
        subjectBrief.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
        SubjectBrief result = subjectBriefService.query(subjectBrief);
        SubjectOptionBO subjectOptionBO = new SubjectOptionBO();
        subjectOptionBO.setSubjectAnswer(result.getSubjectAnswer());
        return subjectOptionBO;
    }
}
